/*
 * RoutesMatrix.java
 *
 * $LastChangedDate$
 * $LastChangedRevision$
 * Vicente J. Ferrer Dalmau
 * < vicente@jdalmau.es >
 *
 * This class defines all the distances between the cities in the problem.
 * For two cities, x and y, the both distances x to y and y to x remain the same.
 */

package com.carpool;


/**
 *
 * @author Vicente J. Ferrer Dalmau
 */
public class RoutesMatrix {

	private float[][] theMatrix;
	private int cities;

	public RoutesMatrix(int cities) {
		theMatrix = new float[cities][cities];
		this.cities = cities;
	}

	public int getCitiesCount() {
		return cities;
	}

	public float getCost(int a, int b) {
		return theMatrix[a][b];
	}

	public void setCost(int a, int b, float cost) {
		theMatrix[a][b] = cost;
	}

	public Object[][] getCosts () {
		Object [][] array = new Object[cities][cities+1];
		for (int i=0; i<cities; i++){
			for (int j=0; j<cities; j++){
				if (j == 0) {
					array[i][0] = i;
					array[i][j+1] = theMatrix[i][j];
				}
				else
					array[i][j+1] = theMatrix[i][j];
			}
		}
		return array;
	}

	public Object[] getCities () {
		Object[] array = new Object[cities+1];
		for (int i=0; i<cities; i++) {
			if (i == 0) {
				array[i] = " ";
				array[i+1] = 0;
			}
			else
				array[i+1] = i;
		}
		return array;
	}

	public String toString() {
		String str = new String();
		for (int i=0; i<cities; i++) {
			for (int j=0; j<cities; j++) {
				if (j == cities - 1)
					str += theMatrix[i][j] + "\n";
				else
					str += theMatrix[i][j] + ", ";
			}
		}
		return str;
	}

}
